//
//  PickerOneView.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/12.
//

#import "PickerTwoView.h"

#define kWholeViewHeight  DimensionBaseIphone6(190)

@interface PickerTwoView ()

@property (nonatomic) UIView *wholeView;

@end

@implementation PickerTwoView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = kBACK_SHADOWCOLOR;
        
        
        [self createBottomView];
        
    }
    return self;
}

- (void)createBottomView{
    self.wholeView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, kWholeViewHeight)];
    self.wholeView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.wholeView];
    
    UIImage *img = [UIImage imageNamed:@"icon_idf13"];
    UIImageView *topImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, DimensionBaseIphone6(img.size.height))];
    [self.wholeView addSubview:topImgView];
    topImgView.image = img;
    topImgView.userInteractionEnabled = YES;
    

    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 18 - 24, topImgView.bottom - 24, 24, 24)];
    [cancelBtn setImage:[UIImage imageNamed:@"icon_idf14"] forState:UIControlStateNormal];
    [cancelBtn setImage:[UIImage imageNamed:@"icon_idf14"] forState:UIControlStateSelected];
    [cancelBtn setImage:[UIImage imageNamed:@"icon_idf14"] forState:UIControlStateHighlighted];
    [cancelBtn addTarget:self action:@selector(clickCacel) forControlEvents:UIControlEventTouchUpInside];
    [topImgView addSubview:cancelBtn];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, topImgView.bottom, kScreenWidth, self.wholeView.size.height - topImgView.bottom)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.wholeView addSubview:backView];
    
    NSArray *imgArr = @[@"icon_idf16",@"icon_idf17"];
    NSArray *titleArr = @[@"Photograph",@"Photo Album"];
    for (int i=0; i<2; i++) {
        UIButton *btn = [[UIButton alloc] init];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
        [btn setTitle:titleArr[i] forState:UIControlStateSelected];
        [btn setTitle:titleArr[i] forState:UIControlStateHighlighted];
        [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateHighlighted];
       
        btn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:14];
        
        if (i == 0) {
            btn.backgroundColor = RGB(241, 243, 242);
            [btn setTitleColor:[UIColor colorWithHexString:@"#00BA60"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#00BA60"] forState:UIControlStateSelected];
            [btn setTitleColor:[UIColor colorWithHexString:@"#00BA60"] forState:UIControlStateHighlighted];

        } else {
            btn.backgroundColor = [UIColor whiteColor];
            [btn setTitleColor:[UIColor colorWithHexString:@"#022D06"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#022D06"] forState:UIControlStateSelected];
            [btn setTitleColor:[UIColor colorWithHexString:@"#022D06"] forState:UIControlStateHighlighted];
        }
        [backView addSubview:btn];
        btn.tag = i;
        [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        btn.frame = CGRectMake(0, i*DimensionBaseIphone6(50) + DimensionBaseIphone6(15), kScreenWidth, DimensionBaseIphone6(50));
    }
}

- (void)clickBtn:(UIButton *)btn{
    [self clickCacel];
    
    if (_callBackInfoStr) {
        _callBackInfoStr(btn.tag);
    }
}

- (void)showBottomView{
    kWeakSelf
    [UIView animateWithDuration:0.25 animations:^{
        
        weakSelf.wholeView.frame = CGRectMake(0, kScreenHeight - kWholeViewHeight, kScreenWidth, kWholeViewHeight);
         
     } completion:^(BOOL finished) {}];
    
}

- (void)clickCacel{
    kWeakSelf
    [UIView animateWithDuration:0.25 animations:^{
        
         weakSelf.wholeView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, kWholeViewHeight);
         
    } completion:^(BOOL finished) {
        
        [self removeFromSuperview];
        
    }];
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
